<?php

/*

Pull my finger (finger.pro.php)

*/
ob_start();
$interactive = 1;
$page_title = "Daily Item";
$rank_check = 1;
include "header.inc.php";

$findFingerPrizes = fetch("SELECT * FROM finger_prizes WHERE game = '$game'");
if ((!$findFingerPrizes[cheap_finger]) OR (!$findFingerPrizes[cheap_finger]) or (!$findFingerPrizes[cheap_finger]))
{
	if ($rank == 7)
	{
		$ifAdmin = "Admins: Click <a href=admin/admin_setup_finger.php?game=$game>here</a> to setup this game!<br>";
	}

	die("$openHTML<p>" . $ifAdmin . "This game is not ready to be played yet.</p>$closeHTML");
}

// Start Check

$checking = "dailyitem";
$limit1 = $datestamp;

$findCheck = fetch("SELECT * FROM checking2 WHERE userid = '$userid' AND check_what = '$checking' AND timestamp = '$limit1' AND game = '$game'");

if ($findCheck[id])
{
	die(header(error("daily_item.php?game=$game","Don't cheat.")));
}

mysql_query("DELETE FROM checking2 WHERE userid = '$userid' AND check_what = '$checking' AND game = '$game'");
mysql_query("INSERT INTO checking2 (userid,check_what,timestamp,game) VALUES ('$userid','$checking','$datestamp','$game')");

// End Check

$num_prizes = rand(1,3);
$prize_1 = explode(", ", $findFingerPrizes[cheap_finger]);
$prize_2 = explode(", ", $findFingerPrizes[good_finger]);
$prize_3 = explode(", ", $findFingerPrizes[great_finger]);

$count_1 = count($prize_1) - 1;
$count_2 = count($prize_2) - 1;
$count_3 = count($prize_3) - 1;
$rand_1 = rand(0,$count_1);
$rand_2 = rand(0,$count_2);
$rand_3 = rand(0,$count_3);

if ($num_prizes == 1)
{
	$first = $prize_1[$rand_1];
	$cookie_1 = fetch("SELECT * FROM items2 WHERE item_name = '$first' AND game = '$game'");
	mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','$cookie_1[id]','$cookie_1[parts]','$game')");
	mysql_query("INSERT INTO pullmyfinger2 (user,date,game) VALUES ('$userid','$datestamp','$game')");

	$message  .= "<img src=$base_url/images/user_images/opg_$game/items/item_$cookie_1[id].gif>";
	$message2 .= "$cookie_1[item_name]";
	die("$openHTML<p align=center>You won a $message2!</p><p align=center>$message</p><p align=center><a href=games.php?game=$game>Back to the Game Room</a></p>$closeHTML");
}
if ($num_prizes == 2)
{
	$first = $prize_1[$rand_1];
	$cookie_1 = fetch("SELECT * FROM items2 WHERE item_name = '$first' AND game = '$game'");
	mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','$cookie_1[id]','$cookie_1[parts]','$game')");
	$second = $prize_2[$rand_2];
	mysql_query("UPDATE members2 SET points=$points+$second WHERE username = '$username' AND game = '$game'");
	mysql_query("INSERT INTO pullmyfinger2 (user,date,game) VALUES ('$userid','$datestamp','$game')");

	$message  .= "<img src=$base_url/images/user_images/opg_$game/items/item_$cookie_1[id].gif>";
	$message2 .= "$cookie_1[item_name]";
	die("$openHTML<p align=center>You won a $message2 and $second $pointVar!</p><p align=center>$message</p><p align=center><a href=games.php?game=$game>Back to the Game Room</a></p>$closeHTML");
}
if ($num_prizes == 3)
{
	$first = $prize_1[$rand_1];
	$cookie_1 = fetch("SELECT * FROM items2 WHERE item_name = '$first' AND game = '$game'");
	mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','$cookie_1[id]','$cookie_1[parts]','$game')");
	$second = round($prize_2[$rand_2]);
	mysql_query("UPDATE members2 SET points=$points+$second WHERE username = '$username' AND game = '$game'");
	$third = $prize_3[$rand_3];
	$cookie_3 = fetch("SELECT * FROM items2 WHERE item_name = '$third' AND game = '$game'");
	mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','$cookie_3[id]','$cookie_3[parts]','$game')");
	mysql_query("DELETE FROM pullmyfinger2 WHERE date != '$datestamp'");
	mysql_query("INSERT INTO pullmyfinger2 (user,date,game) VALUES ('$userid','$datestamp','$game')");

	$message  .= "<img src=$base_url/images/user_images/opg_$game/items/item_$cookie_1[id].gif><img src=$base_url/images/user_images/opg_$game/items/item_$cookie_3[id].gif>";
	$message2 .= "$cookie_1[item_name], and a $cookie_3[item_name]";
	die("$openHTML<p align=center>You won a $message2! You also got $second $pointVar!</p><p align=center>$message</p><p align=center><a href=games.php?game=$game>Back to the Game Room</a></p>$closeHTML");
}

?>